package com.example.demo.controller;

import com.example.demo.domain.Admin;
import com.example.demo.result.RespBean;
import com.example.demo.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/AdminManage")
@CrossOrigin
public class AdminController {
    @Autowired
    private AdminServiceImpl adminService;

    @GetMapping(value = "/findAllAdmin")
    @ResponseBody
    public RespBean findAll(){
        List<Admin> admins;
        admins = adminService.findAll();
        return RespBean.success("success",admins);
    }

    @GetMapping(value = "/findOneAdmin")
    @ResponseBody
    public RespBean findOne(@RequestParam("id") int id){
        Admin admin = adminService.selectAdmin(id);
        return RespBean.success("success",admin);
    }

    @GetMapping(value = "/deleteAdmin")
    @ResponseBody
    public RespBean deleteAdmin(@RequestParam("id") int id){
        adminService.deleteAdmin(id);
        return RespBean.success("success");
    }
    @PostMapping(value = "/updateAdmin")
    @ResponseBody
    public RespBean updateAdmin(@RequestBody Admin admin){
        adminService.updateAdmin(admin);
        return RespBean.success("success");
    }

    @PostMapping(value = "/addAdmin")
    @ResponseBody
    public RespBean addAdmin(@RequestBody Admin admin){
        adminService.addAdmin(admin);
        return RespBean.success("success");
    }
}
